const Router = require("koa-router");
const router = new Router({ prefix: "/api/user" });
const {
  register,
  login,
  changePassword,
  changeNickName,
} = require("../controller/user.controller");
const {
  verifyUserFormData,
  verifyUserRepetition,
  encodePassword,
  verifyLogin,
} = require("../middleware/user.middleware");
const { auth } = require("../middleware/auth.middleware");

// 注册
router.post(
  "/register",
  verifyUserFormData,
  verifyUserRepetition,
  encodePassword,
  register
);

// 登录
router.post("/login", verifyUserFormData, verifyLogin, login);

// 修改密码
router.patch("/", auth, encodePassword, changePassword);

// 修改昵称
router.patch("/nickName", auth, changeNickName);

module.exports = router;
